

CXX	:= g++
LD	:= g++
AR	:= ar
CXXFLAGS := -Wall -Werror -fPIC -O2
INCLUDES = -I . 

TARGET	= libt.so

SOURCES := main.cc


OBJS := $(SOURCES:.cc=.o)
DEPS := $(SOURCES:.cc=.d)

all: prebuild $(TARGET) a.out

$(TARGET): $(OBJS)
	@echo Linking $@ ...
	$(LD) $(OBJS) $(LINKS) $(LIBS) -o$@ -shared -ldl
	@echo -------------------------------------------
	@echo done.

a.out: test.o
	@echo Linking $@ ...
	$(LD) test.o $(LINKS) $(LIBS) -o$@ -lpthread -Wl,-Map,test.map
	@echo -------------------------------------------
	@echo done.

.cpp.o:
	@echo Compling $@ ...
	$(CXX) -c $< $(INCLUDES) $(CXXFLAGS)  -o $@
	@echo -------------------------------------------

.cc.o:
	@echo Compling $@ ...
	$(CXX) -c $< $(INCLUDES) $(CXXFLAGS)  -o $@
	@echo ------------------------------------------

%.d:%.cc
	$(CXX) -MM $< $(INCLUDES) $(CXXFLAGS) -o $@

prebuild:
	#echo -------

include $(DEPS)

clean:
	rm -fr $(OBJS) $(DEPS) $(TARGET) a.out test.o test.map



